{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ef210adc-4333-43b5-bff5-b75b59aee308",
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import pipeline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "445c0491-7d2b-4eb1-b239-e7ceefaab62b",
   "metadata": {},
   "outputs": [],
   "source": [
    "passage = \"The color of animals is by no means a matter of chance; it depends on many considerations, but in the majority of cases tends to protect the animal from danger by rendering it less conspicuous. Perhaps it may be said that if coloring is mainly protective, there ought to be but few brightly colored animals. There are, however, not a few cases in which vivid colors are themselves protective. The kingfisher itself, though so brightly colored, is by no means easy to see. The blue harmonizes with the water, and the bird as it darts along the stream looks almost like a flash of sunlight.\"\n",
    "passage_length = len(passage.split(' '))\n",
    "pipeline_instance = pipeline(\"summarization\", model=\"t5-large\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "01b58899-c004-4ee2-aef7-fae549db2780",
   "metadata": {},
   "outputs": [],
   "source": [
    "pipeline_result = pipeline_instance(passage, max_length=passage_length)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "acaa7c8e-0c29-4e1d-8664-9ffa6bdb602f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the color of animals is by no means a matter of chance; it depends on many considerations . in the majority of cases, coloring tends to protect the animal from danger . there are, however, not a few cases in which vivid colors are themselves protective .\n"
     ]
    }
   ],
   "source": [
    "result = pipeline_result[0][\"summary_text\"]\n",
    "print(result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "chapter09",
   "language": "python",
   "name": "chapter09"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
